package ie.hurley.action;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ActionContext;
import ie.hurley.model.*;
import java.util.List;
import java.util.Map;
import ie.hurley.service.LoginService;

public class LoginAction extends ActionSupport {
	public String username;
	public String password;
	public String type;
	public String message;
	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}
	private LoginService loginService;
	
	
	public LoginService getLoginService() {
		return loginService;
	}

	public void setLoginService(LoginService loginService) {
		this.loginService = loginService;
	}

	public String getUsername() {
		return username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String execute(){
		String result = loginService.login(username, password, type);
		if(result.equals("teacher")){
			addActionMessage(message);
			return teacher_onload();
		}		
		else if(result.equals("student")){
			addActionMessage(message);
			return stu_onload();
		}
		else if(result.equals("manager")){
			addActionMessage(message);
			return manager_onload();
		}
		else{
			addActionMessage(message);
			return result;
		}
	}
	private String teacher_onload(){
//		Map<String,List<students>> students = (Map<String,List<students>>)ActionContext.getContext().get("students");
//		students = loginService.getTeacherMap();
		String myresult = this.message;
		return "teacher";
	}
	private String stu_onload(){
		String myresult = this.message;
		return "student";
	}
	private String manager_onload(){
		String myresult = this.message;
		return "manager";
	}
}
